'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller } = app;
  const jwt = app.middleware.jwt(app.config.jwt)
  router.get('/', controller.home.index);
  router.post('/login', controller.login.login);
  router.get('/allprojects', jwt, controller.projectlist.showAllProjects);
  router.post('/projectlist', jwt, controller.admin.createproject.createProject)
  // 添加api
  router.post('/api',jwt, controller.admin.createapi.createapi)
  // 获取api列表
  router.get('/api', jwt, controller.apilist.showAllApiList)
  // 获取api详情
  router.get('/api/:id', controller.apidetail.apiDetail)
  // 根据projectid获取所有api
  router.get('/apilist/:projectid', jwt, controller.apilist.getApilistByProjectid)
  // 添加用户
  router.post('/user', jwt, controller.admin.createaccount.createAccount)
  // 获取所有用户
  router.get('/user', jwt, controller.admin.getaccount.showAllAccount)
  // 更新用户, 查询条件由前端传递
  router.put('/user', jwt, controller.admin.updateuser.updateUser)
  // 删除用户
  router.delete('/user/:id', controller.admin.deleteaccount.deleteAccount)
  // 是否已经收藏api
  router.get('/isfavapi', jwt, controller.admin.favapi.isFavApi)
  // 收藏api
  router.post('/favapi', jwt, controller.admin.favapi.favapi)
  // 取消收藏api
  router.delete('/favapi/:id', jwt, controller.admin.favapi.deleteFav)
  // 我的收藏
  router.get('/favapi/:username', jwt, controller.admin.favapi.myfav)
  // 我发布的api
  router.get('/mypublish/:username', jwt, controller.admin.mypublish.myPublish)
}